/*
 * Copyright (c) 田梓萱 2021-2022.
 * All Rights Reserved.
 * All codes are protected by China's regulations on the protection of computer software, and infringement must be investigated.
 * 版权所有 (c) 田梓萱 2021-2022.
 * 所有代码均受中国《计算机软件保护条例》保护，本项目已获得软著.
 */

package com.xcl.calculator.slice.Calculate;

import com.huawei.agconnect.crash.AGConnectCrash;
import com.xcl.calculator.Dialog.MyToastDialog;
import com.xcl.calculator.Preference_RW;
import com.xcl.calculator.ResourceTable;
import com.xcl.calculator.XLog;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.components.TextField;
import ohos.agp.utils.Color;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.service.WindowManager;
import ohos.data.distributed.common.KvManagerConfig;
import ohos.data.distributed.common.KvManagerFactory;
import ohos.distributedhardware.devicemanager.DeviceInfo;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
import ohos.multimodalinput.event.KeyEvent;
import ohos.multimodalinput.event.MmiPoint;
import ohos.multimodalinput.event.TouchEvent;
import ohos.utils.PacMap;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

import static com.xcl.calculator.MyApplication.instance_hi;

/**
 * The type Gjd big cal ability slice.
 *
 * @author Xcl
 * @date 2022 /1/29
 * @package com.xcl.calculator.slice.Calculate
 */
public class GJDBigCalAbilitySlice extends AbilitySlice implements Component.TouchEventListener {
    /**
     * The constant label.
     */
    private static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0x00234, "GJDBigCalAbilitySlice");
    /**
     * The B 1.
     */
    private BigDecimal b1;
    /**
     * The Cal 1.
     */
    private String cal1 = null, /**
     * The Cal 2.
     */
    cal2 = null;
    /**
     * The Panduan.
     */
    private int panduan = 0;
    /**
     * The Pdd.
     */
    private int pdd = 0;
    /**
     * The Starx.
     */
    private float starx;
    /**
     * The Stary.
     */
    private float stary;
    /**
     * The Endx.
     */
    private float endx;
    /**
     * The Endy.
     */
    private float endy;

    /**
     * 判断是否为合法小数
     *
     * @param que the que
     * @return boolean boolean
     */
    private static boolean isDecimal0(String que) {
        if (que == null || que.equals("")) return false;
        final String reg = "\\d+(\\.\\d+)?";
        return que.matches(reg);
    }

    /**
     * 开始
     *
     * @param intent the intent
     */
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        try {
            XLog.pd_pd = Preference_RW.ff7_r();
            this.getWindow().addFlags(WindowManager.LayoutConfig.MARK_ALLOW_EXTEND_LAYOUT);
            ohos.data.distributed.device.DeviceInfo localDeviceInfo = KvManagerFactory.getInstance()
                    .createKvManager(new KvManagerConfig((this))).getLocalDeviceInfo();
            int localDeviceType = Integer.parseInt(localDeviceInfo.getType());
            if (localDeviceType == DeviceInfo.DeviceType.PHONE.value()) {
                this.setUIContent(ResourceTable.Layout_bigcalm);
                XLog.info(label, "当前设备类型为手机");
            } else if (localDeviceType == DeviceInfo.DeviceType.TABLET.value()) {
                this.setUIContent(ResourceTable.Layout_bigcalt);
                XLog.info(label, "当前设备类型为平板");
            } else {
                XLog.warn(label, "暂不支持您的设备:(" + localDeviceInfo.getType() + ")");
                this.terminateAbility();
            }

            this.findComponentById(ResourceTable.Id_gjdbigcal).setTouchEventListener(this);
            Text que = (Text) this.findComponentById(ResourceTable.Id_big_que_field);
            que.setEnabled(false);
            this.prepareButtons(ResourceTable.Id_big_que_field);
            this.findComponentById(ResourceTable.Id_back_button).setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component v) {
                    if (GJDBigCalAbilitySlice.this.pdd != 1) {
                        Text question = (TextField) GJDBigCalAbilitySlice.this.findComponentById(ResourceTable.Id_big_que_field);
                        String current = question.getText();
                        if (current.length() > 0) question.setText(current.substring(0, current.length() - 1));
                    }
                }
            });//撤回

            this.findComponentById(ResourceTable.Id_big_cal_button).setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component v) {
                    GJDBigCalAbilitySlice.this.panduan = 2;
                    //TODO:自定义埋点开始，在工程合适位置插入埋点代码
                    PacMap pacMap = new PacMap();
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
                    pacMap.putString("user_uuid", "[" + Preference_RW.uuid.toString() + "]");
                    pacMap.putString("start_num", "[此处不方便统计]");
                    pacMap.putString("end_num", "[=此处不方便统计]");
                    pacMap.putString("se_time", "[" + df.format(new Date()) + "]");
                    instance_hi.onEvent("gjddsjs", pacMap);
                    //TODO:埋点结束
                    if (GJDBigCalAbilitySlice.this.cal1 == null || GJDBigCalAbilitySlice.this.cal1.equals(""))
                        XLog.info(GJDBigCalAbilitySlice.label, "无事发生");
                    else if (que.getText().equals("") || que.getText() == null) {
                        XLog.info(GJDBigCalAbilitySlice.label, "你tm不能输全？");
                        GJDBigCalAbilitySlice.this.ShowDialog1("数据输入不全!");
                    } else {
                        if (GJDBigCalAbilitySlice.this.cal2 == null || GJDBigCalAbilitySlice.this.cal2.equals(""))
                            if (GJDBigCalAbilitySlice.isDecimal0(que.getText())) {
                                que.setHintColor(Color.GRAY);
                                que.setHint("计算式/结果");
                            } else {
                                que.setHint("请输入正确数据!");
                                que.setHintColor(Color.RED);
                                que.setText("");
                            }
                        else GJDBigCalAbilitySlice.this.b1 = new BigDecimal(GJDBigCalAbilitySlice.this.cal2);
                        if (GJDBigCalAbilitySlice.isDecimal0(que.getText())) {
                            BigDecimal bbb;
                            bbb = new BigDecimal(que.getText());
                            que.setHintColor(Color.GRAY);
                            que.setHint("计算式/结果");
                            if (GJDBigCalAbilitySlice.this.pdd == 1) XLog.info(GJDBigCalAbilitySlice.label, "无事发生");
                            else if (GJDBigCalAbilitySlice.this.cal1.equals("+")) {
                                GJDBigCalAbilitySlice.this.cal1 = "";
                                que.setText(GJDBigCalAbilitySlice.this.b1.add(bbb).toString());
                                GJDBigCalAbilitySlice.this.cal2 = que.getText();
                                GJDBigCalAbilitySlice.this.pdd = 1;
                            } else if (GJDBigCalAbilitySlice.this.cal1.equals("-")) {
                                GJDBigCalAbilitySlice.this.cal1 = "";
                                que.setText(GJDBigCalAbilitySlice.this.b1.subtract(bbb).toString());
                                GJDBigCalAbilitySlice.this.cal2 = que.getText();
                                GJDBigCalAbilitySlice.this.pdd = 1;
                            } else if (GJDBigCalAbilitySlice.this.cal1.equals("×")) {
                                GJDBigCalAbilitySlice.this.cal1 = "";
                                que.setText(GJDBigCalAbilitySlice.this.b1.multiply(bbb).toString());
                                GJDBigCalAbilitySlice.this.cal2 = que.getText();
                                GJDBigCalAbilitySlice.this.pdd = 1;
                            } else if (GJDBigCalAbilitySlice.this.cal1.equals("÷")) {
                                if (bbb.doubleValue() == 0.0) {
                                    GJDBigCalAbilitySlice.this.cal1 = "";
                                    que.setText("除数不能为零");
                                    GJDBigCalAbilitySlice.this.cal2 = "0.0";
                                } else {
                                    GJDBigCalAbilitySlice.this.cal1 = "";
                                    que.setText(GJDBigCalAbilitySlice.this.b1.divide(bbb, 20, BigDecimal.ROUND_HALF_UP).toString());
                                    GJDBigCalAbilitySlice.this.cal2 = que.getText();
                                }
                                GJDBigCalAbilitySlice.this.pdd = 1;
                            }
                        } else {
                            que.setHint("请输入正确数据!");
                            que.setHintColor(Color.RED);
                            que.setText("");
                        }
                    }

                }
            });//计算
            this.findComponentById(ResourceTable.Id_ac_button).setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component v) {
                    que.setText("");
                    GJDBigCalAbilitySlice.this.cal1 = null;
                    GJDBigCalAbilitySlice.this.cal2 = null;
                    GJDBigCalAbilitySlice.this.pdd = 0;
                    GJDBigCalAbilitySlice.this.panduan = 3;
                    que.setHintColor(Color.GRAY);
                    que.setHint("计算式/结果");
                }
            });//清空
            this.findComponentById(ResourceTable.Id_badd_button).setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component v) {
                    GJDBigCalAbilitySlice.this.panduan = 2;
                    GJDBigCalAbilitySlice.this.pdd = 0;
                    if (GJDBigCalAbilitySlice.this.cal1 == null || GJDBigCalAbilitySlice.this.cal1.equals(""))
                        if (que.getText() == null || que.getText().equals(""))
                            GJDBigCalAbilitySlice.this.ShowDialog1("请先输入一个数字!");
                        else if (GJDBigCalAbilitySlice.isDecimal0(que.getText())) {
                            GJDBigCalAbilitySlice.this.b1 = new BigDecimal(que.getText());
                            GJDBigCalAbilitySlice.this.cal1 = "+";
                            que.setText("");
                            que.setHintColor(Color.GRAY);
                            que.setHint("计算式/结果");
                        } else {
                            que.setHint("请输入正确数据!");
                            que.setHintColor(Color.RED);
                            que.setText("");
                        }
                    else if (que.getText() == null || que.getText().equals(""))
                        GJDBigCalAbilitySlice.this.ShowDialog1("请输入数字!");
                    else if (GJDBigCalAbilitySlice.isDecimal0(que.getText())) {
                        BigDecimal bbb;
                        bbb = new BigDecimal(que.getText());
                        que.setHintColor(Color.GRAY);
                        que.setHint("计算式/结果");
                        if (GJDBigCalAbilitySlice.this.cal2 == null || GJDBigCalAbilitySlice.this.cal2.equals("")) {

                        } else GJDBigCalAbilitySlice.this.b1 = new BigDecimal(GJDBigCalAbilitySlice.this.cal2);
                        if (GJDBigCalAbilitySlice.this.cal1.equals("+")) {
                            GJDBigCalAbilitySlice.this.cal1 = "+";
                            que.setText(GJDBigCalAbilitySlice.this.b1.add(bbb).toString());
                            GJDBigCalAbilitySlice.this.cal2 = que.getText();
                        } else if (GJDBigCalAbilitySlice.this.cal1.equals("-")) {
                            GJDBigCalAbilitySlice.this.cal1 = "+";
                            que.setText(GJDBigCalAbilitySlice.this.b1.subtract(bbb).toString());
                            GJDBigCalAbilitySlice.this.cal2 = que.getText();
                        } else if (GJDBigCalAbilitySlice.this.cal1.equals("×")) {
                            GJDBigCalAbilitySlice.this.cal1 = "+";
                            que.setText(GJDBigCalAbilitySlice.this.b1.multiply(bbb).toString());
                            GJDBigCalAbilitySlice.this.cal2 = que.getText();
                        } else if (GJDBigCalAbilitySlice.this.cal1.equals("÷")) if (bbb.doubleValue() == 0.0) {
                            que.setText("除数不能为零");
                            GJDBigCalAbilitySlice.this.cal2 = "0.0";
                        } else {
                            GJDBigCalAbilitySlice.this.cal1 = "+";
                            que.setText(GJDBigCalAbilitySlice.this.b1.divide(bbb, 20, BigDecimal.ROUND_HALF_UP).toString());
                            GJDBigCalAbilitySlice.this.cal2 = que.getText();
                        }
                    } else {
                        que.setHint("请输入正确数据!");
                        que.setHintColor(Color.RED);
                        que.setText("");
                    }
                }
            });//+
            this.findComponentById(ResourceTable.Id_bminus_button).setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component v) {
                    GJDBigCalAbilitySlice.this.panduan = 2;
                    GJDBigCalAbilitySlice.this.pdd = 0;
                    XLog.warn(GJDBigCalAbilitySlice.label, "cal1=" + GJDBigCalAbilitySlice.this.cal1 + ",cal2=" + GJDBigCalAbilitySlice.this.cal2 + ",zzz=" + que.getText());
                    if (GJDBigCalAbilitySlice.this.cal1 == null || GJDBigCalAbilitySlice.this.cal1.equals(""))
                        if (que.getText() == null || que.getText().equals(""))
                            GJDBigCalAbilitySlice.this.ShowDialog1("请先输入一个数字!");
                        else if (GJDBigCalAbilitySlice.isDecimal0(que.getText())) {
                            GJDBigCalAbilitySlice.this.b1 = new BigDecimal(que.getText());
                            GJDBigCalAbilitySlice.this.cal1 = "-";
                            que.setText("");
                            que.setHintColor(Color.GRAY);
                            que.setHint("计算式/结果");
                        } else {
                            que.setHint("请输入正确数据!");
                            que.setHintColor(Color.RED);
                            que.setText("");
                        }
                    else if (que.getText() == null || que.getText().equals(""))
                        GJDBigCalAbilitySlice.this.ShowDialog1("请输入数字!");
                    else if (GJDBigCalAbilitySlice.isDecimal0(que.getText())) {
                        BigDecimal bbb;
                        bbb = new BigDecimal(que.getText());
                        que.setHintColor(Color.GRAY);
                        que.setHint("计算式/结果");
                        if (GJDBigCalAbilitySlice.this.cal2 == null || GJDBigCalAbilitySlice.this.cal2.equals("")) {
                        } else GJDBigCalAbilitySlice.this.b1 = new BigDecimal(GJDBigCalAbilitySlice.this.cal2);
                        if (GJDBigCalAbilitySlice.this.cal1.equals("+")) {
                            GJDBigCalAbilitySlice.this.cal1 = "-";
                            que.setText(GJDBigCalAbilitySlice.this.b1.add(bbb).toString());
                            GJDBigCalAbilitySlice.this.cal2 = que.getText();
                        } else if (GJDBigCalAbilitySlice.this.cal1.equals("-")) {
                            GJDBigCalAbilitySlice.this.cal1 = "-";
                            que.setText(GJDBigCalAbilitySlice.this.b1.subtract(bbb).toString());
                            GJDBigCalAbilitySlice.this.cal2 = que.getText();
                        } else if (GJDBigCalAbilitySlice.this.cal1.equals("×")) {
                            GJDBigCalAbilitySlice.this.cal1 = "-";
                            que.setText(GJDBigCalAbilitySlice.this.b1.multiply(bbb).toString());
                            GJDBigCalAbilitySlice.this.cal2 = que.getText();
                        } else if (GJDBigCalAbilitySlice.this.cal1.equals("÷")) if (bbb.doubleValue() == 0.0) {
                            que.setText("除数不能为零");
                            GJDBigCalAbilitySlice.this.cal2 = "0.0";
                        } else {
                            GJDBigCalAbilitySlice.this.cal1 = "-";
                            que.setText(GJDBigCalAbilitySlice.this.b1.divide(bbb, 20, BigDecimal.ROUND_HALF_UP).toString());
                            GJDBigCalAbilitySlice.this.cal2 = que.getText();
                        }

                    } else {
                        que.setHint("请输入正确数据!");
                        que.setHintColor(Color.RED);
                        que.setText("");
                    }

                }
            });//-
            this.findComponentById(ResourceTable.Id_bmul_button).setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component v) {
                    GJDBigCalAbilitySlice.this.panduan = 2;
                    GJDBigCalAbilitySlice.this.pdd = 0;
                    XLog.warn(GJDBigCalAbilitySlice.label, "cal1=" + GJDBigCalAbilitySlice.this.cal1 + ",cal2=" + GJDBigCalAbilitySlice.this.cal2 + ",zzz=" + que.getText());
                    if (GJDBigCalAbilitySlice.this.cal1 == null || GJDBigCalAbilitySlice.this.cal1.equals(""))
                        if (que.getText() == null || que.getText().equals(""))
                            GJDBigCalAbilitySlice.this.ShowDialog1("请先输入一个数字!");
                        else if (GJDBigCalAbilitySlice.isDecimal0(que.getText())) {
                            GJDBigCalAbilitySlice.this.b1 = new BigDecimal(que.getText());
                            GJDBigCalAbilitySlice.this.cal1 = "×";
                            que.setText("");
                            que.setHintColor(Color.GRAY);
                            que.setHint("计算式/结果");
                        } else {
                            que.setHint("请输入正确数据!");
                            que.setHintColor(Color.RED);
                            que.setText("");
                        }
                    else if (que.getText() == null || que.getText().equals(""))
                        GJDBigCalAbilitySlice.this.ShowDialog1("请输入数字!");
                    else if (GJDBigCalAbilitySlice.isDecimal0(que.getText())) {
                        BigDecimal bbb;
                        bbb = new BigDecimal(que.getText());
                        que.setHintColor(Color.GRAY);
                        que.setHint("计算式/结果");
                        if (GJDBigCalAbilitySlice.this.cal2 == null || GJDBigCalAbilitySlice.this.cal2.equals("")) {
                        } else GJDBigCalAbilitySlice.this.b1 = new BigDecimal(GJDBigCalAbilitySlice.this.cal2);
                        if (GJDBigCalAbilitySlice.this.cal1.equals("+")) {
                            GJDBigCalAbilitySlice.this.cal1 = "×";
                            que.setText(GJDBigCalAbilitySlice.this.b1.add(bbb).toString());
                            GJDBigCalAbilitySlice.this.cal2 = que.getText();
                        } else if (GJDBigCalAbilitySlice.this.cal1.equals("-")) {
                            GJDBigCalAbilitySlice.this.cal1 = "×";
                            que.setText(GJDBigCalAbilitySlice.this.b1.subtract(bbb).toString());
                            GJDBigCalAbilitySlice.this.cal2 = que.getText();
                        } else if (GJDBigCalAbilitySlice.this.cal1.equals("×")) {
                            GJDBigCalAbilitySlice.this.cal1 = "×";
                            que.setText(GJDBigCalAbilitySlice.this.b1.multiply(bbb).toString());
                            GJDBigCalAbilitySlice.this.cal2 = que.getText();
                        } else if (GJDBigCalAbilitySlice.this.cal1.equals("÷")) if (bbb.doubleValue() == 0.0) {
                            que.setText("除数不能为零");
                            GJDBigCalAbilitySlice.this.cal2 = "0.0";
                        } else {
                            GJDBigCalAbilitySlice.this.cal1 = "×";
                            que.setText(GJDBigCalAbilitySlice.this.b1.divide(bbb, 20, BigDecimal.ROUND_HALF_UP).toString());
                            GJDBigCalAbilitySlice.this.cal2 = que.getText();
                        }
                    } else {
                        que.setHint("请输入正确数据!");
                        que.setHintColor(Color.RED);
                        que.setText("");
                    }
                }
            });//×
            this.findComponentById(ResourceTable.Id_bchu_button).setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component v) {
                    GJDBigCalAbilitySlice.this.panduan = 2;
                    GJDBigCalAbilitySlice.this.pdd = 0;
                    XLog.warn(GJDBigCalAbilitySlice.label, "cal1=" + GJDBigCalAbilitySlice.this.cal1 + ",cal2=" + GJDBigCalAbilitySlice.this.cal2 + ",zzz=" + que.getText());
                    if (GJDBigCalAbilitySlice.this.cal1 == null || GJDBigCalAbilitySlice.this.cal1.equals(""))
                        if (que.getText() == null || que.getText().equals(""))
                            GJDBigCalAbilitySlice.this.ShowDialog1("请先输入一个数字!");
                        else if (GJDBigCalAbilitySlice.isDecimal0(que.getText())) {
                            GJDBigCalAbilitySlice.this.b1 = new BigDecimal(que.getText());
                            GJDBigCalAbilitySlice.this.cal1 = "÷";
                            que.setText("");
                            que.setHintColor(Color.GRAY);
                            que.setHint("计算式/结果");
                        } else {
                            que.setHint("请输入正确数据!");
                            que.setHintColor(Color.RED);
                            que.setText("");
                        }
                    else if (que.getText() == null || que.getText().equals(""))
                        GJDBigCalAbilitySlice.this.ShowDialog1("请输入数字!");
                    else if (GJDBigCalAbilitySlice.isDecimal0(que.getText())) {
                        BigDecimal bbb;
                        bbb = new BigDecimal(que.getText());
                        que.setHintColor(Color.GRAY);
                        que.setHint("计算式/结果");
                        if (GJDBigCalAbilitySlice.this.cal2 == null || GJDBigCalAbilitySlice.this.cal2.equals("")) {
                        } else GJDBigCalAbilitySlice.this.b1 = new BigDecimal(GJDBigCalAbilitySlice.this.cal2);
                        if (GJDBigCalAbilitySlice.this.cal1.equals("+")) {
                            GJDBigCalAbilitySlice.this.cal1 = "÷";
                            que.setText(GJDBigCalAbilitySlice.this.b1.add(bbb).toString());
                            GJDBigCalAbilitySlice.this.cal2 = que.getText();
                        } else if (GJDBigCalAbilitySlice.this.cal1.equals("-")) {
                            GJDBigCalAbilitySlice.this.cal1 = "÷";
                            que.setText(GJDBigCalAbilitySlice.this.b1.subtract(bbb).toString());
                            GJDBigCalAbilitySlice.this.cal2 = que.getText();
                        } else if (GJDBigCalAbilitySlice.this.cal1.equals("×")) {
                            GJDBigCalAbilitySlice.this.cal1 = "÷";
                            que.setText(GJDBigCalAbilitySlice.this.b1.multiply(bbb).toString());
                            GJDBigCalAbilitySlice.this.cal2 = que.getText();
                        } else if (GJDBigCalAbilitySlice.this.cal1.equals("÷")) if (bbb.doubleValue() == 0.0) {
                            que.setText("除数不能为零");
                            GJDBigCalAbilitySlice.this.cal2 = "0.0";
                        } else {
                            GJDBigCalAbilitySlice.this.cal1 = "÷";
                            que.setText(GJDBigCalAbilitySlice.this.b1.divide(bbb, 20, BigDecimal.ROUND_HALF_UP).toString());
                            GJDBigCalAbilitySlice.this.cal2 = que.getText();
                        }
                    } else {
                        que.setHint("请输入正确数据!");
                        que.setHintColor(Color.RED);
                        que.setText("");
                    }
                }
            });//÷
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 展示数据
     *
     * @param text1 the text 1
     */
    private void ShowDialog(String text1) {
        try {
            ohos.data.distributed.device.DeviceInfo localDeviceInfo = KvManagerFactory.getInstance()
                    .createKvManager(new KvManagerConfig((this))).getLocalDeviceInfo();
            int localDeviceType = Integer.parseInt(localDeviceInfo.getType());
            if (localDeviceType == DeviceInfo.DeviceType.PHONE.value()) {
                new MyToastDialog(this.getContext(), text1, ResourceTable.Graphic_xtoast_framem, 36, 25)
                        .setDuration(120)
                        .setAlignment(LayoutAlignment.BOTTOM)
                        .setOffset(0, 100)
                        .show();
                XLog.info(label, "当前设备类型为手机");
            } else if (localDeviceType == DeviceInfo.DeviceType.TABLET.value()) {
                new MyToastDialog(this.getContext(), text1, ResourceTable.Graphic_xtoast_framet, 43, 37)
                        .setDuration(120)
                        .setAlignment(LayoutAlignment.BOTTOM)
                        .setOffset(0, 100)
                        .show();
                XLog.info(label, "当前设备类型为平板");
            } else {
                XLog.warn(label, "暂不支持您的设备:(" + localDeviceInfo.getType() + ")");
                this.terminateAbility();
            }
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 展示数据1
     *
     * @param text1 the text 1
     */
    private void ShowDialog1(String text1) {
        try {
            ohos.data.distributed.device.DeviceInfo localDeviceInfo = KvManagerFactory.getInstance()
                    .createKvManager(new KvManagerConfig((this))).getLocalDeviceInfo();
            int localDeviceType = Integer.parseInt(localDeviceInfo.getType());
            if (localDeviceType == DeviceInfo.DeviceType.PHONE.value()) {
                new MyToastDialog(this.getContext(), text1, ResourceTable.Graphic_xtoast_frame1m, 36, 25)
                        .setDuration(120)
                        .setAlignment(LayoutAlignment.BOTTOM)
                        .setOffset(0, 100)
                        .show();
                XLog.info(label, "当前设备类型为手机");
            } else if (localDeviceType == DeviceInfo.DeviceType.TABLET.value()) {
                new MyToastDialog(this.getContext(), text1, ResourceTable.Graphic_xtoast_frame1t, 43, 37)
                        .setDuration(120)
                        .setAlignment(LayoutAlignment.BOTTOM)
                        .setOffset(0, 100)
                        .show();
                XLog.info(label, "当前设备类型为平板");
            } else {
                XLog.warn(label, "暂不支持您的设备:(" + localDeviceInfo.getType() + ")");
                this.terminateAbility();
            }
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 移动
     *
     * @param component  the component
     * @param touchEvent the touch event
     * @return boolean boolean
     */
    @Override
    public boolean onTouchEvent(Component component, TouchEvent touchEvent) {
        try {
            int action = touchEvent.getAction();
            if (action == TouchEvent.PRIMARY_POINT_DOWN) {
                MmiPoint position = touchEvent.getPointerPosition(0);
                this.starx = position.getX();
                this.stary = position.getY();
            } else if (action == TouchEvent.PRIMARY_POINT_UP) {
                MmiPoint position = touchEvent.getPointerPosition(0);
                this.endx = position.getX();
                this.endy = position.getY();
                if (this.starx > this.endx && Math.abs(this.stary - this.endy) < 123 && Math.abs(this.starx - this.endx) > 156) {
                    this.ShowDialog("到头了...");
                    XLog.info(label, "左滑了");
                } else if (this.starx < this.endx && Math.abs(this.stary - this.endy) < 123 && Math.abs(this.starx - this.endx) > 156) {
                    /*无参--页面跳转开始*/
                    Intent intent = new Intent();
                    Operation operation = new Intent.OperationBuilder()
                            .withDeviceId("")
                            .withBundleName(this.getBundleName())
                            .withAbilityName("com.xcl.calculator.Ability.Calculate.CalMenuAbility")
                            .build();// 通过Intent中的OperationBuilder类构造operation对象，指定设备标识（空串表示当前设备）、应用包名、Ability名称
                    intent.setOperation(operation);// 把operation设置到intent中
                    this.startAbility(intent);
                    this.onBackPressed();
                    /*页面跳转结束--无参*/
                    XLog.info(label, "右滑了");
                } else //this.ShowDialog("到头了...");
                    if (this.stary > this.endy && Math.abs(this.starx - this.endx) < 123 && Math.abs(this.stary - this.endy) > 156)
                        XLog.info(label, "上滑了");
                    else //this.ShowDialog("到头了...");
                        if (this.stary < this.endy && Math.abs(this.starx - this.endx) < 123 && Math.abs(this.stary - this.endy) > 156)
                            XLog.info(label, "下滑了");
                        else XLog.info(label, "无效滑动（请直一点！）");
            } else XLog.info(label, "滑动中");
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
        return true;
    }

    /**
     * 初始化按钮
     *
     * @param i the
     */
    private void prepareButtons(int i) {
        try {
            int[] direct_button = {
                    ResourceTable.Id_bnumber0_button,//0
                    ResourceTable.Id_bnumber1_button,//1
                    ResourceTable.Id_bnumber2_button,//2
                    ResourceTable.Id_bnumber3_button,//3
                    ResourceTable.Id_bnumber4_button,//4
                    ResourceTable.Id_bnumber5_button,//5
                    ResourceTable.Id_bnumber6_button,//6
                    ResourceTable.Id_bnumber7_button,//7
                    ResourceTable.Id_bnumber8_button,//8
                    ResourceTable.Id_bnumber9_button,//9
                    ResourceTable.Id_bdot_button,//.
            };
            for (int id : direct_button)
                this.findComponentById(id).setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component v) {
                        Text qqq = (TextField) GJDBigCalAbilitySlice.this.findComponentById(i);
                        qqq.setHintColor(Color.GRAY);
                        qqq.setHint("计算式/结果");
                        if (GJDBigCalAbilitySlice.this.panduan == 2) {
                            qqq.setText(((Button) v).getText());
                            GJDBigCalAbilitySlice.this.panduan = 3;
                        } else qqq.setText(qqq.getText() + ((Button) v).getText());
                    }
                });
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 退出
     *
     * @param keyCode  the key code
     * @param keyEvent the key event
     * @return boolean boolean
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent keyEvent) {
        if (keyCode == KeyEvent.KEY_BACK) {
            this.ShowDialog("程序退出成功，感谢您的使用!");
            this.terminateAbility();
            return true;
        }
        return super.onKeyDown(keyCode, keyEvent);
    }
}